package com.bank.trade_records.qu_money.controller;


import com.bank.trade_records.qu_money.entity.QuMoney;
import com.bank.trade_records.qu_money.service.QuMoneyService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
//@CrossOrigin(origins = "http://localhost:8081") // 允许来自该源的请求
@RequestMapping("/tradeRecords/QuMoney")
public class QuMoneyController {

    @Autowired
    private QuMoneyService quMoneyService;

    // 获取单个用户
    @GetMapping("/{id}")
    public QuMoney getQuMoneyById(@PathVariable Long id) {
        return quMoneyService.getQuMoneyById(id);
    }

    // 添加用户
    @PostMapping
    public boolean addQuMoney(@RequestBody QuMoney quMoney) {
        return quMoneyService.addQuMoney(quMoney);
    }

    // 更新用户
    @PutMapping("/{id}")
    public boolean updateQuMoney(@PathVariable Long id,@RequestBody QuMoney quMoney) {
        quMoney.setId(id); // 假设前端传来的QuMoney对象不包含ID，需要手动设置
        return quMoneyService.updateQuMoney(quMoney);
    }

    // 删除用户
    @DeleteMapping("/{id}")
    public boolean deleteQuMoneyById(@PathVariable Long id) {
        return quMoneyService.deleteQuMoneyById(id);
    }

    // 获取所有用户
    @GetMapping
    public List<QuMoney> getAllQuMoneys() {
        return quMoneyService.getAllQuMoneys();
    }

    // 批量插入用户
    @PostMapping("/batch")
    public boolean batchInsert(@RequestBody  List<QuMoney> quMoneyList) {
        return quMoneyService.batchInsert(quMoneyList);
    }

    @GetMapping("/page")
    public Page<QuMoney> getQuMoneyPage(@RequestParam(value = "page", defaultValue = "1") int page,
                                        @RequestParam(value = "size", defaultValue = "10") int size) {
        Page<QuMoney> quMoneyPage = new Page<>(page, size);
        return quMoneyService.getQuMoneyPage(quMoneyPage);
    }

    @PostMapping("/sum")
    public List< Object> getDailyTransactionAmounts(){
        return quMoneyService.getDailyTransactionAmounts();
    };


    // 其他接口...
}
